package com.niiwoo.civet.trade.service.dubbo.databackflow;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dangdang.ddframe.rdb.sharding.api.HintManager;
import com.dangdang.ddframe.rdb.sharding.hint.HintManagerHolder;
import com.niiwoo.civet.trade.dao.entity.Project;
import com.niiwoo.civet.trade.dao.entity.ProjectLoanDeviceInfo;
import com.niiwoo.civet.trade.dto.request.databackflow.*;
import com.niiwoo.civet.trade.enums.ProjectFromSourceEnum;
import com.niiwoo.civet.trade.enums.RepaymentTypeEnum;
import com.niiwoo.civet.trade.service.databackflow.TianChengDataBackFlowDubboService;
import com.niiwoo.civet.trade.service.local.common.ProjectCommonService;
import com.niiwoo.civet.trade.service.local.databackflow.TianChengDataBackFlowLocalService;
import com.niiwoo.civet.user.dto.LinkManDubboInfoDTO;
import com.niiwoo.civet.user.dto.UserPersonalDubboInfoDTO;
import com.niiwoo.civet.user.dto.UserProfessionDubboInfoDTO;
import com.niiwoo.civet.user.dto.request.DataBackFlowRetryTaskRequestDTO;
import com.niiwoo.civet.user.dto.response.UserBasicInfoResponseDTO;
import com.niiwoo.civet.user.enums.LinkManRelationEnum;
import com.niiwoo.civet.user.enums.TCFromTypeEnum;
import com.niiwoo.civet.user.enums.UserEnum;
import com.niiwoo.civet.user.enums.UserPersonalEnum;
import com.niiwoo.civet.user.service.UserBasicInfoDubboService;
import com.niiwoo.civet.user.service.UserDataDubboService;
import com.niiwoo.civet.user.service.dataflow.DataBackFlowRetryDubboService;
import com.niiwoo.civet.user.service.dataflow.UserDataBackFlowDubboService;
import com.niiwoo.tripod.base.component.PrivacyMasks;
import com.niiwoo.tripod.provider.exception.BizException;
import com.niiwoo.tripod.tiancheng.component.TianchengDataFlowService;
import com.niiwoo.tripod.tiancheng.enums.FunctionCodeEnum;
import com.niiwoo.tripod.tiancheng.request.common.TianchengUapRequest;
import com.niiwoo.tripod.tiancheng.request.df.AddressListRequest;
import com.niiwoo.tripod.tiancheng.request.df.LoanInfoRequest;
import com.niiwoo.tripod.tiancheng.request.df.PersonalInfoRequest;
import com.niiwoo.tripod.tiancheng.request.df.ProfessionInfoRequest;
import com.niiwoo.tripod.tiancheng.response.common.TianchengUapResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;

/**
 * 天称数据回流服务实现
 *
 * @author xueyuke
 * @date 2017-11-30
 */
@Slf4j
@Service(version = "1.0.0", validation = "true")
public class TianChengDataBackFlowDubboServiceImpl implements TianChengDataBackFlowDubboService {

    @Autowired
    TianchengDataFlowService tianchengDataFlowService;
    @Autowired
    ProjectCommonService projectCommonService;
    @Reference(version = "1.0.0")
    private UserDataDubboService userDataDubboService;
    @Reference(version = "1.0.0")
    private UserBasicInfoDubboService userBasicInfoDubboService;
    @Reference(version = "1.0.0")
    private UserDataBackFlowDubboService userDataBackFlowDubboService;
    @Reference(version = "1.0.0")
    private DataBackFlowRetryDubboService dataBackFlowRetryDubboService;
    @Autowired
    PrivacyMasks privacyMasks;
    @Autowired
    private TianChengDataBackFlowLocalService tianChengDataBackFlowLocalService;

    /**
     * 通讯录回流
     *
     * @param addressListBackFlowRequestDTO
     */
    @Override
    public void addressList(AddressListBackFlowRequestDTO addressListBackFlowRequestDTO) {
        try {
            if (addressListBackFlowRequestDTO.getAddressList() == null || addressListBackFlowRequestDTO.getAddressList().size() == 0) {
                log.error("通讯录前端回流,用户ID={},发生异常,原因是通讯录列表为空.", addressListBackFlowRequestDTO.getUserId());
                throw new BizException("TRD40003");
            }
            AddressListRequest addressListRequest = new AddressListRequest();
            addressListRequest.setUserId(addressListBackFlowRequestDTO.getUserId());
            addressListRequest.setDeviceId(addressListBackFlowRequestDTO.getDeviceId());
            addressListRequest.setOs(addressListBackFlowRequestDTO.getOs());
            addressListRequest.setEquipmentStatus(addressListBackFlowRequestDTO.getEquipmentStatus());

            List<AddressListRequest.Address> address4RequestList = new ArrayList<AddressListRequest.Address>();
            for (AddressListBackFlowRequestDTO.Address address : addressListBackFlowRequestDTO.getAddressList()) {
                AddressListRequest.Address address4Request = new AddressListRequest.Address();
                address4Request.setRemark(address.getRemark());
                address4Request.setMobile(address.getMobile());

                address4RequestList.add(address4Request);
            }
            addressListRequest.setAddressList(address4RequestList);

            log.info("通讯录前端回流,用户ID={},发起天称请求参数={}", addressListBackFlowRequestDTO.getUserId(), JSON.toJSONString(addressListBackFlowRequestDTO));
            CompletableFuture<TianchengUapResponse> addressListCompletableFuture = tianchengDataFlowService.addressList(addressListRequest);
            TianchengUapResponse tianchengUapResponse = null;
            try {
                tianchengUapResponse = addressListCompletableFuture.get(2, TimeUnit.SECONDS);
                log.info("通讯录前端回流,用户ID={},天称响应结果={}", addressListBackFlowRequestDTO.getUserId(), JSON.toJSONString(tianchengUapResponse));
            } catch (Exception e) {
                log.error("通讯录前端回流,用户ID={},发生系统异常,错误信息={}", addressListBackFlowRequestDTO.getUserId(), e);
                throw new RuntimeException(e);
            }

            if (!isBackFlowSuccess(tianchengUapResponse.getStatus())) {
                log.error("通讯录前端回流,用户ID={},回流不成功,天称响应结果={}", addressListBackFlowRequestDTO.getUserId(), JSON.toJSONString(tianchengUapResponse));
                throw new BizException("TRD40001");
            }
        }catch(Exception e){
            log.error("通讯录前端回流,用户ID={},发生系统异常,原因={}", addressListBackFlowRequestDTO.getUserId(),e);
        }
    }

    @Override
    public void abortiveProject(AbortiveProjectBackFlowRequestDTO abortiveProjectBackFlowRequestDTO) {
        try {
            tianChengDataBackFlowLocalService.abortiveProject(abortiveProjectBackFlowRequestDTO);
        } catch (Exception e) {
            log.error("流标事件回流,标的ID={},发生系统异常,原因={}", abortiveProjectBackFlowRequestDTO.getBid(), e);
        }
    }

    @Override
    public void projecctStatusChange(ProjectStatusChangeBackFlowRequestDTO projectStatusChangeBackFlowRequestDTO) {
        try {
            tianChengDataBackFlowLocalService.projecctStatusChange(projectStatusChangeBackFlowRequestDTO);
        } catch (Exception e) {
            log.error("标的状态变更事件回流,标的ID={},发生系统异常,原因={}", projectStatusChangeBackFlowRequestDTO.getProjectId(), e);
        }
    }

    @Override
    public void personalInfo(PersonalInfoBackFlowRequestDTO personalInfoBackFlowRequestDTO) {
        String userId = personalInfoBackFlowRequestDTO.getUserId();
        log.info("TianChengDataBackFlowDubboServiceImpl.personalInfo userId={} start", userId);

        UserPersonalDubboInfoDTO userPersonalDubboInfoDTO = userDataDubboService.userPersonalInfo(userId);
        log.info("TianChengDataBackFlowDubboServiceImpl.personalInfo userId={},userPersonalDubboInfoDTO={}", userId, JSON.toJSONString(userPersonalDubboInfoDTO));
        UserBasicInfoResponseDTO userBasicInfo = userBasicInfoDubboService.getUserBasicInfo(userId);
        log.info("TianChengDataBackFlowDubboServiceImpl.personalInfo userId={},userBasicInfo={}", userId, JSON.toJSONString(userBasicInfo));

        PersonalInfoRequest tianchengRequest = new PersonalInfoRequest();
        tianchengRequest.setUserId(userId);//用户id
        tianchengRequest.setMobilePhone(userBasicInfo.getMobileNo());//手机号
        Integer eduLevel = UserPersonalEnum.UserEduLevelEnum.getByLevel(userPersonalDubboInfoDTO.getEducationLevel()).getTianChengUserEduLevelEnum().getType();
        tianchengRequest.setDegreeType(eduLevel);//学历--学历类型(1大专以下,2大专,3本科,4硕士,5博士及以上)
        Integer maritalStatus = UserPersonalEnum.UserMaritalStatusEnum.getByLevel(userPersonalDubboInfoDTO.getMaritalStatus()).getTianChengUserMaritalStatusEnum().getStatus();
        UserEnum.RegisterChannel registerChannel = UserEnum.RegisterChannel.enumOf(userBasicInfo.getRegisterChannel().byteValue());
        tianchengRequest.setFromType(TCFromTypeEnum.getTCFromTypeFromRegisterChannel(registerChannel)); ////用户来源(0-未知 1团贷网，2好帮贷，3你我金融，4房宝宝，5现金动车，6量化派 7 借钱快 8 融360 9卡牛)
        tianchengRequest.setMaritalStatus(maritalStatus);//婚姻状况--(0未婚,1已婚,2离异,3丧偶)
        tianchengRequest.setLivingProvince(userPersonalDubboInfoDTO.getLivingProvince());//现居住地址省份
        tianchengRequest.setLivingCity(userPersonalDubboInfoDTO.getLivingCity());//现居住地址城市
        tianchengRequest.setLivingArea(userPersonalDubboInfoDTO.getLivingArea());//现居住地址区
        tianchengRequest.setLivingAddress(userPersonalDubboInfoDTO.getLivingAddress());//详细地址
        tianchengRequest.setEmail(userPersonalDubboInfoDTO.getEmail());//电子邮箱
        tianchengRequest.setUpdateTime(userPersonalDubboInfoDTO.getUpdateTime().getTime() * 1000l);//更新时间--微秒时间戳
        //联系人初始化
        this.personalInfoInitLinkManInfo(userPersonalDubboInfoDTO, tianchengRequest);
        log.info("TianChengDataBackFlowDubboServiceImpl.personalInfo userId={},tianchengRequest={}", userId, JSON.toJSONString(tianchengRequest));
        tianchengDataFlowService.personalInfo(tianchengRequest).whenComplete(dataBackFlowRetryCallBack(userId, FunctionCodeEnum.PERSONAL_INFO_FLOW, tianchengRequest));
        log.info("TianChengDataBackFlowDubboServiceImpl.personalInfo userId={} end", userId);
    }

    private BiConsumer<TianchengUapResponse, Throwable> dataBackFlowRetryCallBack(String userId, FunctionCodeEnum functionCodeEnum, TianchengUapRequest tianchengUapRequest) {
        log.info("dataBackFlowRetryCallBack.userId={} start", userId);
        return (res, ex) -> {
            log.info("dataBackFlowRetryCallBack.userId={},functionCodeEnum={},res={},ex={}", userId, JSON.toJSONString(functionCodeEnum), JSON.toJSONString(res), ex);
            try {
                if (ex != null || !"0".equals(res.getStatus())) {
                    log.info("dataBackFlowRetryCallBack.userId={},tianchengUapRequest={}", userId, JSON.toJSONString(tianchengUapRequest));
                    DataBackFlowRetryTaskRequestDTO dataBackFlowRetryTaskRequestDTO = new DataBackFlowRetryTaskRequestDTO();
                    dataBackFlowRetryTaskRequestDTO.setUserId(userId);
                    dataBackFlowRetryTaskRequestDTO.setFunctionCode(functionCodeEnum.getBodyFunctionCode());
                    dataBackFlowRetryTaskRequestDTO.setBackflowData(JSON.toJSONString(tianchengUapRequest));
                    dataBackFlowRetryDubboService.saveDataFlowRetryTask(dataBackFlowRetryTaskRequestDTO);
                }
            } catch (Exception e) {
                log.error("dataBackFlowRetryCallBack异常，userId={},functionCodeEnum={},tianchengUapRequest={}", userId, JSON.toJSONString(functionCodeEnum), JSON.toJSONString(tianchengUapRequest), e);
            }
            log.info("dataBackFlowRetryCallBack.userId={},res={} end", userId, JSON.toJSONString(res));
        };
    }

    //联系人初始化
    private void personalInfoInitLinkManInfo(UserPersonalDubboInfoDTO userPersonalDubboInfoDTO, PersonalInfoRequest tianchengRequest) {
        List<LinkManDubboInfoDTO> linkManInfoList = userPersonalDubboInfoDTO.getLinkManInfoList();
        if (CollectionUtils.isEmpty(linkManInfoList)) {
            return;
        }
        List<PersonalInfoRequest.UserRelationRequest> userRelations = new ArrayList<>();
        for (LinkManDubboInfoDTO linkMan : linkManInfoList) {
            PersonalInfoRequest.UserRelationRequest userRelationReq = new PersonalInfoRequest.UserRelationRequest();
            userRelationReq.setUserId(String.valueOf(userPersonalDubboInfoDTO.getUserId()));
            userRelationReq.setContactRelation(LinkManRelationEnum.getByEventType(linkMan.getRelation()).getDesc());
            userRelationReq.setContactName(linkMan.getName());
            userRelationReq.setContactPhone(linkMan.getMobileNo());
            userRelationReq.setUpdateTime(linkMan.getUpdateTime().getTime());
            userRelations.add(userRelationReq);
        }
        tianchengRequest.setUserRelations(userRelations);
    }

    @Override
    public void professionInfo(ProfessionInfoBackFlowRequestDTO professionInfoBackFlowRequestDTO) {
        String userId = professionInfoBackFlowRequestDTO.getUserId();
        String logHead = "TianChengDataBackFlowDubboServiceImpl.professionInfo userId=" + userId + " ";
        log.info(logHead + "start");
        UserProfessionDubboInfoDTO userProfessionDubboInfoDTO = userDataDubboService.userProfessionInfo(userId);
        UserBasicInfoResponseDTO userBasicInfo = userBasicInfoDubboService.getUserBasicInfo(userId);

        ProfessionInfoRequest tianchengRequest = new ProfessionInfoRequest();

        tianchengRequest.setUserId(userProfessionDubboInfoDTO.getUserId()); //用户id
        tianchengRequest.setMobilePhone(userBasicInfo.getMobileNo());  //手机号
        tianchengRequest.setCompanyName(userProfessionDubboInfoDTO.getCompanyName());  //公司名称
        tianchengRequest.setCompanyProvince(userProfessionDubboInfoDTO.getCompanyProvince()); //单位地址省份
        tianchengRequest.setCompanyCity(userProfessionDubboInfoDTO.getCompanyCity());  //单位地址城市
        tianchengRequest.setCompanyArea(userProfessionDubboInfoDTO.getCompanyArea());  //单位地址区
        tianchengRequest.setCompanyAddress(userProfessionDubboInfoDTO.getCompanyAddress());  //单位详细地址
        tianchengRequest.setCompanyTel(userProfessionDubboInfoDTO.getCompanyPhone());  //单位电话
        tianchengRequest.setDeparment(userProfessionDubboInfoDTO.getDepartment()); //部门
        tianchengRequest.setPosition(userProfessionDubboInfoDTO.getPosition()); //职务
        //tianchengRequest.setIncome();    //收入（信用借）
        //tianchengRequest.setWorkYears();      //工作年限(信用借)
        //tianchengRequest.setWorkTotalYears();//工作总工龄(信用借)
        tianchengRequest.setCreateTime(userProfessionDubboInfoDTO.getCreateTime().getTime()); //创建时间
        tianchengRequest.setUpdateTime(userProfessionDubboInfoDTO.getUpdateTime().getTime()); //更新时间
        log.info(logHead + "tianchengRequest=" + JSON.toJSONString(tianchengRequest));
        tianchengDataFlowService.professionInfo(tianchengRequest).whenComplete(dataBackFlowRetryCallBack(userId, FunctionCodeEnum.PROFESSION_INFO_FLOW, tianchengRequest));
        log.info(logHead + "end");
    }

    @Override
    public void loanInfo(LoanInfoBackFlowRequestDTO loanInfoBackFlowRequestDTO) {
        String userId = loanInfoBackFlowRequestDTO.getUserId();
        Long projectId = loanInfoBackFlowRequestDTO.getProjectId();
        String logHead = "TianChengDataBackFlowDubboServiceImpl.loanInfo userId=" + userId + ",projectId=" + projectId + " ";
        log.info(logHead + "start");

        Project project = projectCommonService.selectByUserIdAndProjectIdFromMaster(userId, projectId);
        ProjectLoanDeviceInfo projectLoanDeviceInfo = projectCommonService.queryLoanDeviceInfoFromMaster(projectId);

        log.info("卡牛借款数据回流{}", JSONObject.toJSONString(project));
        LoanInfoRequest tianchengRequest = new LoanInfoRequest();

        long createTime = project.getCreateTime().getTime() * 1000;
        tianchengRequest.setUserId(userId);//借款用户id-必输
        tianchengRequest.setMobilePhone(this.decryptString(project.getBorrowMobile()));
        tianchengRequest.setBid(String.valueOf(project.getProjectId()));//标id-必输
        tianchengRequest.setTitle(project.getTitle());//借款标题
        tianchengRequest.setBorrowedAmount(project.getHandAmount().floatValue());//借款金额
        tianchengRequest.setLendRates(project.getBorrowRate().floatValue());//借款利率
        tianchengRequest.setCreateDate(createTime);//借款时间
        tianchengRequest.setRepaymentType(RepaymentTypeEnum.enumOf(project.getRepaymentType()).getTianChengRepaymentTypeEnum().getValue());//还款方式--0到期还本息,1每月付息到期还本,2每月等额本息
        tianchengRequest.setBorrowingMonth(project.getDeadline());//借款时长(按月)
        tianchengRequest.setTotalPeriods(project.getDeadline());//借款总期数
        //tianchengRequest.setAmountUsedDesc(project.get);//借款描述
        tianchengRequest.setType(13);//类型--13:极速借，14：信用借，15体验标
        tianchengRequest.setCreditType(Integer.valueOf(project.getCreditType()));//授信类型--0:其它,1:社保,2:芝麻,3:学历
        tianchengRequest.setFromSource(ProjectFromSourceEnum.enumOf(project.getFromSource()).getTianChengFromSourceEnum().getType());//标的来源--0、APP，1、H5活动，2、H5极速借,3、H5淘宝极速借，4、融360
        tianchengRequest.setLongitude(project.getLongitude());//经度
        tianchengRequest.setLatitude(project.getLatitude());//纬度
        tianchengRequest.setApplyTime(createTime);//更新时间

        if (projectLoanDeviceInfo != null) {
            //tianchengRequest.setMapType();//地图类型--（0-高德1-百度）
            //tianchengRequest.setMacAddress();//Mac地址
            //tianchengRequest.setOperators();//运营商
            //tianchengRequest.setDownChannel();//下载渠道（渠道号）
            //tianchengRequest.setAppVersion();//App版本
            //tianchengRequest.setSimMobilePhone();//当前设备sim卡手机号
            //tianchengRequest.setOsVersion();//操作系统版本
            //tianchengRequest.setResolution();//屏幕分辨率
            //tianchengRequest.setPhoneModel();//设备型号
            tianchengRequest.setIpAddress(projectLoanDeviceInfo.getIp());//Ip地址
            tianchengRequest.setWifiSSID(projectLoanDeviceInfo.getWifiSsid());//WIFISSID
            tianchengRequest.setDeviceId(projectLoanDeviceInfo.getDeviceId());//设备唯一id
            tianchengRequest.setOs(projectLoanDeviceInfo.getOs());//当前设备操作系统类型
            tianchengRequest.setBrand(projectLoanDeviceInfo.getBrandType());//设备品牌
            tianchengRequest.setEquipmentStatus(this.byteConvertToInteger(projectLoanDeviceInfo.getDeviceStatus()));//设备状态(是否越狱orroot)--0-否1-是
            tianchengRequest.setDualSim(this.byteConvertToInteger(projectLoanDeviceInfo.getDsds()));//是否双卡双待--0-否1-是
            tianchengRequest.setMapType(this.byteConvertToInteger(projectLoanDeviceInfo.getMapType()));//地图类型（0-高德 1-百度）
        }

        log.info(logHead + "tianchengRequest=" + JSON.toJSONString(tianchengRequest));
        tianchengDataFlowService.loanInfo(tianchengRequest).whenComplete(dataBackFlowRetryCallBack(userId, FunctionCodeEnum.LOAN_INFO_FLOW, tianchengRequest));
        log.info(logHead + "end");
    }

    private Integer byteConvertToInteger(Byte data) {
        return data == null ? null : Integer.valueOf(data);
    }

    /**
     * 借款提交相关数据回流
     *
     * @param loanApplyDataBackFlowRequestDTO
     */
    @Override
    public void loanApplyDataBackFlow(LoanApplyDataBackFlowRequestDTO loanApplyDataBackFlowRequestDTO) {
        String userId = loanApplyDataBackFlowRequestDTO.getUserId();
        Long projectId = loanApplyDataBackFlowRequestDTO.getProjectId();

        try {
            log.info("loanApplyDataBackFlow userId={},projectId={} personalInfo start!", userId, projectId);
            PersonalInfoBackFlowRequestDTO personalInfoBackFlowRequestDTO = new PersonalInfoBackFlowRequestDTO();
            personalInfoBackFlowRequestDTO.setUserId(userId);
            this.personalInfo(personalInfoBackFlowRequestDTO);
            log.info("loanApplyDataBackFlow userId={},projectId={} personalInfo success end!", userId, projectId);
        } catch (Exception e) {
            log.info("loanApplyDataBackFlow userId={},projectId={} personalInfo error", userId, projectId, e);
        }

        try {
            log.info("loanApplyDataBackFlow userId={},projectId={} professionInfo start!", userId, projectId);
            ProfessionInfoBackFlowRequestDTO professionInfoBackFlowRequestDTO = new ProfessionInfoBackFlowRequestDTO();
            professionInfoBackFlowRequestDTO.setUserId(userId);
            this.professionInfo(professionInfoBackFlowRequestDTO);
            log.info("loanApplyDataBackFlow userId={},projectId={} professionInfo success end!", userId, projectId);
        } catch (Exception e) {
            log.info("loanApplyDataBackFlow userId={},projectId={} professionInfo error", userId, projectId, e);
        }

        try {
            log.info("loanApplyDataBackFlow userId={},projectId={} loanInfo start!", userId, projectId);
            LoanInfoBackFlowRequestDTO loanInfoBackFlowRequestDTO = new LoanInfoBackFlowRequestDTO();
            loanInfoBackFlowRequestDTO.setUserId(userId);
            loanInfoBackFlowRequestDTO.setProjectId(projectId);
            this.loanInfo(loanInfoBackFlowRequestDTO);
            log.info("loanApplyDataBackFlow userId={},projectId={} loanInfo success end!", userId, projectId);
        } catch (Exception e) {
            log.info("loanApplyDataBackFlow userId={},projectId={} loanInfo error", userId, projectId, e);
        }

        try {
            log.info("loanApplyDataBackFlow userId={},projectId={} identityAuth start!", userId, projectId);
            userDataBackFlowDubboService.identityAuthBackFlow(userId);
            log.info("loanApplyDataBackFlow userId={},projectId={} identityAuth success end!", userId, projectId);
        } catch (Exception e) {
            log.info("loanApplyDataBackFlow userId={},projectId={} identityAuth error", userId, projectId, e);
        }


        try {
            log.info("loanApplyDataBackFlow userId={},projectId={} bankInfo start!", userId, projectId);
            userDataBackFlowDubboService.bankInfoBackFlow(userId);
            log.info("loanApplyDataBackFlow userId={},projectId={} bankInfo success end!", userId, projectId);
        } catch (Exception e) {
            log.info("loanApplyDataBackFlow userId={},projectId={} bankInfo error", userId, projectId, e);
        }
    }

    /**
     * 回流成功?0成功 1失败 2：超时或返回为空
     *
     * @param status
     * @return
     */
    private boolean isBackFlowSuccess(String status) {
        return status.equals("0");
    }

    /**
     * 解密字符串
     *
     * @param str 密文
     */
    private String decryptString(String str) {
        if (!StringUtils.hasText(str)) {
            return null;
        }
        return privacyMasks.decryptPrivacy(str);
    }
}
